package vlt.el.main;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import vlt.el.db.DBConnection;
import vlt.el.db.SQLGenerator;
import vlt.el.util.Config;

public class InitialLoad {

	public static void main(String[] args) throws FileNotFoundException, IOException, SQLException, ClassNotFoundException {
		DBConnection db = new DBConnection();
		try{
		Config config = Config.getInstance();
		config.reloadConfigProperties();
		db.connectOrig(true);
		SQLGenerator sqlGenerator = new SQLGenerator();
		String owner = config.getConfigProperty("database.orig.owner");
		String table = config.getConfigProperty("database.orig.table");

		
		int threads = Integer.parseInt(config.getConfigProperty("app.threads"));
		
		List<String[]> ids = sqlGenerator.splitTableById(owner, table, db.getConnOrig(), threads);
		int i=0;
		for (String[] id : ids){
			InitialLoadT main = new InitialLoadT();
			main.setInitialId(id[0]);
			main.setFinalId(id[1]);
			main.setThread(i++);
			Thread t = new Thread(main);
			t.start();
		}
		}finally{
			try {
				db.disconnectOrig();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}
